# Observables

The `@devicescript/observables` [builtin](/developer/packages) module provides a lightweight reactive observable framework, a limited subset of [RxJS](https://rxjs.dev).
We highly recommend reviewing the RxJS documentation for deeper discussions about observables.

For in-depth tutorials about observables, see [RxJS](https://rxjs.dev/).

## Setup

Import `@devicescript/observables` to enable the APIs.

```ts skip
import "@devicescript/observables"
```

## Operators

Observable operators apply transformation between observable data stream. They can be combined using the `pipe`
method to create complex data processing pipeline. Many (most) operators are adapted from [Rxjs](https://rxjs.dev/guide/operators).

```ts
import { Temperature } from "@devicescript/core"
import { threshold, throttleTime } from "@devicescript/observables"

const thermometer = new Temperature()
// create a stream of temperature readings
const temperature = thermometer.reading.pipe(
    threshold(0.1), // at least 0.1deg change
    throttleTime(10000) // at most one update per 10s
)
temperature.subscribe(t => console.log(t))
```
